package com.muqi.app.user.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import static nl.qbusict.cupboard.CupboardFactory.cupboard;

/**
 * 根据bean建表。bean的属性名会映射为表的列名。bean中需要一个Long型的_id属性作为表的主键
 *
 */
public class CupboardSQLiteOpenHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "my_qlearn.db";  
    private static final int DATABASE_VERSION = 1;  
  
    static {  
        // 注册Bean
        cupboard().register(CmdLoaclMessage.class);
        cupboard().register(MyClassStudent.class);  
        cupboard().register(MyClassBean.class); 
        cupboard().register(ChildBean.class); 
        cupboard().register(TreeLeaf.class); 
    }  
  
    public CupboardSQLiteOpenHelper(Context context) {  
        super(context, DATABASE_NAME, null, DATABASE_VERSION);  
    }  
  
    @Override  
    public void onCreate(SQLiteDatabase db) {  
        //建表
        cupboard().withDatabase(db).createTables();  
    }  
  
    @Override  
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  
        cupboard().withDatabase(db).upgradeTables();  
    }
}
